package com.ncs.base.task.controller;

import java.util.Date;

import org.quartz.CronScheduleBuilder;
import org.quartz.CronTrigger;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.ncs.base.task.config.UserJob;
import com.ncs.base.task.entity.AddRequest;
import com.ncs.base.task.entity.ResultBO;
import com.ncs.base.task.service.TimedTaskService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@Api(value = "定时任务", tags = {"定时任务"})
@RestController
@RequestMapping("/quartz")
public class VehicleJobController {

    @Autowired
    private TimedTaskService timedTaskService;

    @ApiOperation("添加定时任务")
    @PostMapping("/add")
    public ResultBO add(@Validated @RequestBody AddRequest addRequest) throws Exception {

        System.out.println("传过来的添加定时任务参数为:{}" + addRequest);
        ResultBO resultBO = timedTaskService.addQuartzJob(addRequest);
        return resultBO;
    }

    @ApiOperation("删除定时任务")
    @GetMapping("/delete/{taskId}")
    public ResultBO delete(@ApiParam(value = "定时任务id", required = true) @PathVariable String taskId) throws Exception {

        System.out.println("传过来的删除定时任务id为:{}" + taskId);
        ResultBO resultBO = timedTaskService.deleteQuartzJob(Integer.valueOf(taskId));
        return resultBO;
    }

    @ApiOperation("修改定时任务")
    @PostMapping("/update")
    public ResultBO update(@Validated @RequestBody AddRequest addRequest) throws Exception {

        ResultBO resultBO = timedTaskService.updateQuartzJob(addRequest);
        return resultBO;
    }

    @ApiOperation("查询定时任务")
    @GetMapping("/list")
    public ResultBO list(@Validated @RequestBody AddRequest addRequest) throws Exception {

        ResultBO resultBO = timedTaskService.selectQuartzJobList(addRequest);
        return resultBO;
    }
    
    
    
    
    
    @RequestMapping("/demo1")
    @ApiOperation("测试")
	@ResponseBody
	public ResultBO demo() throws Exception {
        ResultBO resultBO = timedTaskService.demo();
        return resultBO;

	}
	
    
    
}
